//old alpha 6 weapons

/*RFW.WP_pistol = RFW.AddWeapon(2, { //only add weapons NOT in runtime (e.g no commands to add weapons) only add weapons in whitespace (if they're touching the very left edge of the screen)
	["WeaponName"] = "Magnum",
	["PickupAmmo"] = 20,
	["AmmoType"] = 1,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"MGNM", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"MGNM", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"MGNM", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"MGNM", "B", 1+1, action = RFW.WA_PistolShot},
				{"MGNM", "C", 1+1},
				{"MGNM", "D", 1+1},
				{"MGNM", "A", 4+1},
				{"MGNM", "A", 1+1, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			}
		}
	}
)

RFW.WP_shotgun = RFW.AddWeapon(3, {
	["WeaponName"] = "Shotgun",
	["PickupAmmo"] = 8,
	["AmmoType"] = 2,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"TREN", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"TREN", "A", 0+1, action = RFW.WA_Lower},
				{"Loop"}
			},
			
			["Raise"] = {
				{"TREN", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TREN", "B", 2+1, action = RFW.WA_SGShot},
				{"TREN", "C", 1+1},
				{"TREN", "D", 1+1},
				{"TREN", "E", 1+1},
				{"TREN", "F", 1+1},
				{"TREN", "G", 1+1},
				{"TREN", "I", 1+1},
				{"TREN", "K", 0+1, action = RFW.WA_SGRel},
				{"TREN", "M", 1+1},
				{"TREN", "N", 2+1},
				{"TREN", "L", 1+1},
				{"TREN", "K", 1+1},
				{"TREN", "J", 1+1},
				{"TREN", "I", 1+1},
				{"TREN", "H", 1+1},
				{"TREN", "G", 2+1},
				{"TREN", "G", 1+1, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			},
		}
	}
)

RFW.WP_karasawa = RFW.AddWeapon(6, {
	["WeaponName"] = "Karasawa",
	["PickupAmmo"] = 40,
	["AmmoType"] = 4,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"KRSW", "F", 2+1, action = RFW.WA_KarasawaFlash, colormap = "KRSF", colorframe = "F"},
				{"KRSW", "G", 2+1, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "H", 2+1, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "I", 2+1, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "J", 6+1, colormap = "KRSF", colorframe = "J"},
				{"KRSW", "I", 2+1, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "H", 2+1, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "G", 2+1, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "F", 2+1, colormap = "KRSF", colorframe = "F"},
				{"Loop"}
			},*/
			
			/*["KFlash"] = {
				{"MGNM", "F", 2},
				{"MGNM", "G", 2},
				{"MGNM", "H", 2},
				{"MGNM", "I", 2},
				{"MGNM", "J", 6},
				{"MGNM", "I", 2},
				{"MGNM", "H", 2},
				{"MGNM", "G", 2},
				{"MGNM", "F", 2}
			},*/
			
			/*["Lower"] = {
				{"KRSW", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"KRSW", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"KRSW", "B", 2+1, action = RFW.WA_KarasawaShot, colormap = "KRSF", colorframe = "B"},
				{"KRSW", "C", 2+1, colormap = "KRSF", colorframe = "C"},
				{"KRSW", "D", 2+1, colormap = "KRSF", colorframe = "D"},
				{"KRSW", "E", 2+1, colormap = "KRSF", colorframe = "E"},
				{"KRSW", "A", 1+1+7},
				{"Goto", "Ready"}
			},*/
			
			/*["Flash"] = {
				{"KRSF", "B", 2},
				{"KRSF", "C", 2},
				{"KRSF", "D", 2},
				{"KRSF", "E", 2},
				//{"KRSF", "A", 1}
			},*/
/*		}
	}
)

RFW.WP_chaingun = RFW.AddWeapon(4, {
	["WeaponName"] = "Chaingun",
	["PickupAmmo"] = 20,
	["AmmoType"] = 1,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"CGUN", "E", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"CGUN", "E", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"CGUN", "E", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"CGUN", "A", 2, action = RFW.WA_ChaingunShot},
				{"CGUN", "B", 2},
				{"CGUN", "C", 2, action = RFW.WA_ChaingunShot},
				{"CGUN", "D", 2},
				{"CGUN", "E", 2, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			}
		}
	}
)

RFW.WP_grenadelauncher = RFW.AddWeapon(5, {
	["WeaponName"] = "Grenade-Launcher",
	["PickupAmmo"] = 5,
	["AmmoType"] = 3,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"GREN", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"GREN", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"GREN", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"GREN", "B", 3, action = RFW.WA_GrenadeShot},
				{"GREN", "A", 12},
				{"GREN", "A", 6, action = RFW.WA_GrenadeClose},*/
				/*{"GREN", "D", 2, action = RFW.WA_GrenadeOpen},
				{"GREN", "F", 2+1},
				{"GREN", "G", 2+1},
				{"GREN", "H", 3+1, action = RFW.WA_GrenadeLoad},
				{"GREN", "F", 2+1},
				//{"GREN", "E", 2+1},
				{"GREN", "D", 2, action = RFW.WA_GrenadeClose},*/
				/*{"Goto", "Ready"}
			},
		}
	}
)

RFW.WP_rocketlauncher = RFW.AddWeapon(5, {
	["WeaponName"] = "Rocket-Launcher",
	["PickupAmmo"] = 5,
	["AmmoType"] = 3,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"ROCK", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"ROCK", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"ROCK", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"ROCK", "E", 2, action = RFW.WA_RocketShot},
				{"ROCK", "F", 2},
				{"ROCK", "G", 2},
				{"ROCK", "A", 16},
				{"ROCK", "B", 2},
				{"ROCK", "C", 2},
				{"ROCK", "D", 2},
				{"Goto", "Ready"}
			},
		}
	}
)

RFW.WP_railgun = RFW.AddWeapon(6, {
	["WeaponName"] = "Railgun",
	["PickupAmmo"] = 40,
	["AmmoType"] = 4,
	["MinAmmo"] = 10,
		["States"] = {
			["Ready"] = {
				{"RLGN", "A", 2, action = RFW.WA_KarasawaFlash, colormap = "RLFL", colorframe = "A"}, //all the animation here is done through colormaps
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "B"},
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "C"},
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "A"},
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "B"},
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "C"},
				{"Loop"}
			},
			
			["Lower"] = {
				{"RLGN", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"RLGN", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"RLGN", "B", 2, action = RFW.WA_RailFire, colormap = "RLFL", colorframe = "F"},
				{"RLGN", "C", 2, colormap = "RLFL", colorframe = "G"},
				{"RLGN", "D", 2, colormap = "RLFL", colorframe = "H"},
				{"RLGN", "A", 21+6}, //+1
				{"RLGN", "A", 21, action = RFW.WA_RailCharge}, //+1
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "D"}, //+1
				{"RLGN", "A", 4, action = RFW.WA_Refire, colormap = "RLFL", colorframe = "D"}, //+1
				{"Goto", "Ready"}
			},
		}
	}
)*/

//new alpha 6 weapons

//function RFW.WA_Noise(p) //this is placeholder, add proper sound propagation eventually
	
//end

freeslot("sfx_pistol")
freeslot("sfx_shotfr")
freeslot("sfx_shotpm")
freeslot("sfx_grclos")

freeslot("SPR_WPVW")

RFW.WP_pistol = RFW.AddWeapon(2, { //only add weapons NOT in runtime (e.g no commands to add weapons) only add weapons in whitespace (if they're touching the very left edge of the screen)
	["WeaponName"] = "Magnum",
	["BobFunc"] = RFW.Bob_RampageBobSmallWeaps,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 0,
	["PickupAmmo"] = 20,
	["AmmoType"] = 1,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"MGNM", "A", 1, colormap = "MGNC", colorframe = "A"},
				{"Loop"}
			},
			
			["Lower"] = {
				{"MGNM", "A", 0+1, action = RFW.WA_Lower, colormap = "MGNC", colorframe = "A"}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"MGNM", "A", 0+1, action = RFW.WA_Raise, colormap = "MGNC", colorframe = "A"},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_pistol},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"MGNM", "B", 1+1, action = RFW.WA_CustomBullet, arg1 = 5, arg2 = 15, arg3 = FU, arg4 = FU, arg5 = 4096*FU, arg6 = true, arg7 = false, colormap = "MGNC", colorframe = "B", brightmap = "MGNB", brightframe = "B"},
				{"MGNM", "C", 1+1, colormap = "MGNC", colorframe = "C"},
				{"MGNM", "D", 1+1, colormap = "MGNC", colorframe = "D"},
				{"MGNM", "A", 4+1, colormap = "MGNC", colorframe = "A"},
				{"MGNM", "A", 1+1, action = RFW.WA_Refire, colormap = "MGNC", colorframe = "A"},
				{"Goto", "Ready"}
			},
		}
	}
)

RFW.WP_shotgun = RFW.AddWeapon(3, {
	["WeaponName"] = "Shotgun",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 1,
	//["BobFunc"] = RFW.Bob_Bobstyle2,
	["PickupAmmo"] = 8,
	["AmmoType"] = 2,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"TREN", "A", 1, colormap = "TRNC", colorframe = "A"},
				{"Loop"}
			},
			
			["Lower"] = {
				{"TREN", "A", 0+1, action = RFW.WA_Lower, colormap = "TRNC", colorframe = "A"},
				{"Loop"}
			},
			
			["Raise"] = {
				{"TREN", "A", 0+1, action = RFW.WA_Raise, colormap = "TRNC", colorframe = "A"},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_shotfr},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"TREN", "B", 2+1, action = RFW.WA_CustomSpread, arg1 = 5, arg2 = 15, arg3 = 3*FU/2, arg4 = FU, arg5 = 4096*FU, arg6 = 7, arg7 = false, brightmap = "TRNB", brightframe = "B"},
				{"TREN", "C", 1+1, brightmap = "TRNB", brightframe = "C"},
				{"TREN", "D", 1+1, colormap = "TRNC", colorframe = "D"},
				{"TREN", "E", 1+1, colormap = "TRNC", colorframe = "E"},
				{"TREN", "F", 1+1, colormap = "TRNC", colorframe = "F"},
				{"TREN", "G", 1+1, colormap = "TRNC", colorframe = "G"},
				{"TREN", "I", 1+1},
				{"TREN", "K", 0+1, action = RFW.WA_PlaySound, arg1 = sfx_shotpm},
				{"TREN", "M", 1+1},
				{"TREN", "N", 2+1},
				{"TREN", "L", 1+1},
				{"TREN", "K", 1+1},
				{"TREN", "J", 1+1},
				{"TREN", "I", 1+1},
				{"TREN", "H", 1+1, colormap = "TRNC", colorframe = "H"},
				{"TREN", "G", 2+1, colormap = "TRNC", colorframe = "G"},
				{"TREN", "G", 1+1, action = RFW.WA_Refire, colormap = "TRNC", colorframe = "G"},
				{"Goto", "Ready"}
			},
		}
	}
)

function RFW.WA_ChaingunShot(p)
	local angle1 = 0
	local angle2 = 0
	if p.refire then
		angle1 = FixedAngle(P_RandomRange(-2*FU, 2*FU))
		angle2 = FixedAngle(P_RandomRange(-FU, FU))
	end
	RFW.WA_UseAmmo(p)
	//old damage P_RandomRange(5, 15)
	RFW.WA_BasicHitscan(p, P_RandomRange(5, 15), p.mo.angle + angle1, p.aiming + angle2, 8192*FU, 2048)
	S_StartSound(p.mo, sfx_CHAING)
end

freeslot("sfx_chaing")

RFW.WP_chaingun = RFW.AddWeapon(4, {
	["WeaponName"] = "Chaingun",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 2,
	["PickupAmmo"] = 20,
	["AmmoType"] = 1,
	["MinAmmo"] = 2,
		["States"] = {
			["Ready"] = {
				{"CGUN", "E", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"CGUN", "E", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"CGUN", "E", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_chaing},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"CGUN", "A", 1, action = RFW.WA_CustomBullet, arg1 = 5, arg2 = 15, arg3 = 2*FU, arg4 = FU, arg5 = 4096*FU, arg6 = true, arg7 = false, brightmap = "CGUB", brightframe = "A"},
				//{"CGUN", "A", 1, action = RFW.WA_ChaingunShot, brightmap = "CGUB", brightframe = "A"},
				{"CGUN", "B", 1, brightmap = "CGUB", brightframe = "A"},
				{"CGUN", "C", 1, brightmap = "CGUB", brightframe = "B"},
				{"CGUN", "D", 1, brightmap = "CGUB", brightframe = "B"},
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_chaing},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"CGUN", "E", 1, action = RFW.WA_CustomBullet, arg1 = 5, arg2 = 15, arg3 = 2*FU, arg4 = FU, arg5 = 4096*FU, arg6 = true, arg7 = false, brightmap = "CGUB", brightframe = "C"},
				//{"CGUN", "E", 1, action = RFW.WA_ChaingunShot, brightmap = "CGUB", brightframe = "C"},
				{"CGUN", "F", 1, brightmap = "CGUB", brightframe = "C"},
				{"CGUN", "G", 1, brightmap = "CGUB", brightframe = "D"},
				{"CGUN", "H", 1, brightmap = "CGUB", brightframe = "D"},
				{"CGUN", "A", 2, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			}
		}
	}
)

RFW.WP_grenadelauncher = RFW.AddWeapon(5, {
	["WeaponName"] = "Grenade-Launcher",
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 4,
	["BobFunc"] = RFW.Bob_RampageBob,
	["PickupAmmo"] = 5,
	["AmmoType"] = 3,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"GREN", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"GREN", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"GREN", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_cannon},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"GREN", "B", 3, action = RFW.WA_CustomProjectileGrenade, arg1 = MT_SHOTGRENADE, arg4 = 6*FU},
				{"GREN", "A", 12},
				{"GREN", "A", 6, action = RFW.WA_PlaySound, arg1 = sfx_grclos},
				{"Goto", "Ready"}
			},
		}
	}
)

RFW.WP_rocketlauncher = RFW.AddWeapon(5, {
	["WeaponName"] = "Rocket-Launcher",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 5,
	["PickupAmmo"] = 5,
	["AmmoType"] = 3,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = {
				{"ROCK", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"ROCK", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"ROCK", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_cannon},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"ROCK", "E", 2, action = RFW.WA_CustomProjectile, arg1 = MT_RMPROCKET},
				{"ROCK", "F", 2},
				{"ROCK", "G", 2},
				{"ROCK", "A", 16},
				{"ROCK", "B", 2},
				{"ROCK", "C", 2},
				{"ROCK", "D", 2},
				{"Goto", "Ready"}
			},
		}
	}
)

freeslot("sfx_karaid", "sfx_karai2", "sfx_railch")

function RFW.WA_PlasmaIdle(p)
	//if (leveltime % 70) then return end
	if S_SoundPlaying(p.mo, sfx_karaid) then return end
	S_StartSound(p.mo, sfx_karaid)
end

function RFW.WA_PlasmaIdle2(p)
	//if (leveltime % 70) then return end
	if S_SoundPlaying(p.mo, sfx_karai2) then return end
	S_StartSound(p.mo, sfx_karai2)
end

function RFW.WA_PlasmaUnidle(p)
	S_StopSoundByID(p.mo, sfx_karaid)
	S_StopSoundByID(p.mo, sfx_karai2)
end

RFW.WP_railgun = RFW.AddWeapon(6, {
	["WeaponName"] = "Railgun",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 6,
	["Priority"] = 1500,
	["PickupAmmo"] = 40,
	["AmmoType"] = 4,
	["MinAmmo"] = 10,
		["States"] = {
			["Ready"] = { //sfx_KARAID
				{"RLGN", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "RLFL", colorframe = "A"}, //all the animation here is done through colormaps
				{"RLGN", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "RLFL", colorframe = "A"},
				{"RLGN", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "RLFL", colorframe = "B"},
				{"RLGN", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "RLFL", colorframe = "B"},
				{"RLGN", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "RLFL", colorframe = "C"},
				{"RLGN", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "RLFL", colorframe = "C"},
				{"Loop"}
			},
			
			["Lower"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"RLGN", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"RLGN", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"RLGN", "B", 2, action = RFW.WA_RailFire, colormap = "RLFL", colorframe = "F"},
				{"RLGN", "C", 2, colormap = "RLFL", colorframe = "G"},
				{"RLGN", "D", 2, colormap = "RLFL", colorframe = "H"},
				{"RLGN", "A", 21+6}, //+1
				{"RLGN", "A", 21, action = RFW.WA_PlaySound, arg1 = sfx_railch}, //+1
				{"RLGN", "A", 2, colormap = "RLFL", colorframe = "D"}, //+1
				{"RLGN", "A", 4, action = RFW.WA_Refire, colormap = "RLFL", colorframe = "D"}, //+1
				{"Goto", "Ready"}
			},
		}
	}
)

freeslot("sfx_axe1", "sfx_axe2")

function RFW.WA_AxeSlash(p)
	//print(1)
	local targetlist = P_AngleRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle, zang = p.aiming, distance = 192*FU, steps = 4, tclip = true, lclip = true, ignore = p.mo, callback2 = P_SpawnMobj, larg = MT_SMOKE}
	//print(2)
	if not next(targetlist) then return false end
	local target = targetlist[1][4]
	if target.type == MT_PLAYER then
		if CanPlayerHurtPlayer(p, target.player, 0) == true then
			for i = 1, P_RandomRange(4, 7) do
				RFW.Bleed(mo)
			end
			Playerdamage(target, p.mo, p.mo, 75, 0, true)
			S_StartSound(p.mo, sfx_axe2)
			return true
		end
	else
		for i = 1, P_RandomRange(1, 3) do
			RFW.SparkCoordinate(target, targetlist[1][1], targetlist[1][2], targetlist[1][3])
		end
		for i = 1, P_RandomRange(4, 7) do
			RFW.Bleed(mo)
		end
		RFW.DirectDamageEnemy(target, p.mo, p.mo, 75, 0)
		S_StartSound(p.mo, sfx_axe2)
		return true
	end
end

RFW.WP_axe = RFW.AddWeapon(1, { //only add weapons NOT in runtime (e.g no commands to add weapons) only add weapons in whitespace (if they're touching the very left edge of the screen)
	["WeaponName"] = "Axe",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 8,
	["PickupAmmo"] = 0,
	["AmmoType"] = 0,
	["MinAmmo"] = 0,
		["States"] = {
			["Ready"] = {
				{"AXEG", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"AXEG", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"AXEG", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"AXEG", "B", 3},
				{"AXEG", "C", 3},
				{"AXEG", "D", 3},
				{"AXEG", "E", 3},
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_axe1},
				{"AXEG", "F", 2, action = RFW.WA_AxeSlash},
				{"AXEG", "G", 2},
				{"AXEG", "H", 2},
				{"AXEG", "I", 2},
				{"AXEG", "J", 2},
				{"AXEG", "K", 2},
				{"Goto", "Ready"}
			},
			
			["AltFire"] = {
				{"FUCK", "A", 1},
				{"FUCK", "B", 1},
				{"FUCK", "C", 1},
				{"FUCK", "D", 15, action = RFW.WA_HarshLanguage},
				{"FUCK", "E", 1},
				{"FUCK", "F", 1},
				{"FUCK", "G", 1},
				{"FUCK", "H", 1},
				{"FUCK", "I", 1},
				{"Goto", "Ready"}
			}
		}
	}
)

freeslot("sfx_knif1", "sfx_knif2", "sfx_knif3")

function RFW.WA_CheckAmbush(mo, target)
	local at = target.angle // angle target is currently facing
	local atp = R_PointToAngle2(mo.x, mo.y, target.x, target.y) // actor to target angle
	local an = atp - at

	if (an > ANGLE_180) then // flip angle if bigger than 180
		an = InvAngle(an)
	end

	if (an < ANGLE_90+ANGLE_22h) // within an angle of 112.5 from each other?
		return true
	end
	return false
end

function RFW.WA_CheckAmbushPoint(x, y, target)
	local at = target.angle // angle target is currently facing
	local atp = R_PointToAngle2(x, y, target.x, target.y) // actor to target angle
	local an = atp - at
	an = $ & ANGLE_MAX

	if (an > ANGLE_180) then // flip angle if bigger than 180
		an = InvAngle(an)
	end

	if (abs(an) < ANGLE_90+ANGLE_22h) // within an angle of 112.5 from each other?
		return true
	end
	return false
end

function RFW.WA_KnifeSlash(p)
	//print(1)
	local targetlist = P_AngleRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle, zang = p.aiming, distance = 96*FU, steps = 4, tclip = true, lclip = true, ignore = p.mo, callback2 = P_SpawnMobj, larg = MT_SMOKE}
	//print(2)
	if not next(targetlist) then return false end
	local target = targetlist[1][4]
	if target.type == MT_PLAYER then
		if CanPlayerHurtPlayer(p, target.player, 0) == true then
			for i = 1, P_RandomRange(1, 3) do
				RFW.Bleed(mo)
			end
			Playerdamage(target, p.mo, p.mo, 15, 0, true)
			S_StartSound(p.mo, sfx_knif2)
			return true
		end
	else
		for i = 1, P_RandomRange(1, 3) do
			RFW.SparkCoordinate(target, targetlist[1][1], targetlist[1][2], targetlist[1][3])
		end
		for i = 1, P_RandomRange(1, 3) do
			RFW.Bleed(mo)
		end
		RFW.DirectDamageEnemy(target, p.mo, p.mo, 15, 0)
		S_StartSound(p.mo, sfx_knif2)
		return true
	end
end

RFW.WP_knife = RFW.AddWeapon(1, { //only add weapons NOT in runtime (e.g no commands to add weapons) only add weapons in whitespace (if they're touching the very left edge of the screen)
	["WeaponName"] = "Knife",
	["BobFunc"] = RFW.Bob_RampageBobSmallWeaps,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 7,
	["PickupAmmo"] = 0,
	["AmmoType"] = 0,
	["MinAmmo"] = 0,
		["States"] = {
			["Ready"] = {
				{"KNFG", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"KNFG", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"KNFG", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"KNFG", "B", 2, action = RFW.WA_PlaySound, arg1 = sfx_knif1},
				{"KNFG", "C", 2, action = RFW.WA_KnifeSlash},
				{"KNFG", "D", 2},
				{"KNFG", "E", 2},
				{"KNFG", "D", 2, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			},
			
			["AltFire"] = {
				{"FUCK", "A", 1},
				{"FUCK", "B", 1},
				{"FUCK", "C", 1},
				{"FUCK", "D", 15, action = RFW.WA_HarshLanguage},
				{"FUCK", "E", 1},
				{"FUCK", "F", 1},
				{"FUCK", "G", 1},
				{"FUCK", "H", 1},
				{"FUCK", "I", 1},
				{"Goto", "Ready"}
			}
		}
	}
)

RFW.WP_enaxe = RFW.AddWeapon(1, {
	["WeaponName"] = "Energy Axe",
	["BobFunc"] = RFW.Bob_RampageBobSmallWeaps,
	["AmmoType"] = 0,
	["Priority"] = 500,
	["MinAmmo"] = 0,
		["States"] = {
			["Ready"] = {
				{"ENHN", "A", 43+1, action = RFW.WA_AxeIdle, colormap = "ENBL", colorframe = "A", colorflags = V_ADD}, //170 tics = ~1.24 seconds for sound effect
				{"Loop"}
			},
			
			["Lower"] = {
				{"ENHN", "A", 0+1, action = RFW.WA_Lower},
				{"Loop"}
			},
			
			["Raise"] = {
				{"ENHN", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			/*["Raise"] = {
				{"ENHN", "J", 1, action = RFW.WA_AxeRaise1},
				{"ENHN", "K", 1},
				{"ENHN", "L", 2},
				{"ENHN", "M", 4},
				{"ENHN", "N", 1, colormap = "ENBL", colorframe = "J"},
				{"ENHN", "O", 1, colormap = "ENBL", colorframe = "K"},
				{"ENHN", "A", 1, action = RFW.WA_Raise, colormap = "ENBL", colorframe = "A"},
				{"Loop"}
			},*/
			
			["Fire"] = {
				{"ENHN", "B", 3+1, action = RFW.WA_AxeLunge, colormap = "ENBL", colorframe = "B", colorflags = V_ADD},
				{"ENHN", "C", 3+1, action = RFW.WA_AxeHit, colormap = "ENBL", colorframe = "C", colorflags = V_ADD},
				{"ENHN", "D", 3+1, colormap = "ENBL", colorframe = "D", colorflags = V_ADD},
				{"ENHN", "E", 3+1, colormap = "ENBL", colorframe = "E", colorflags = V_ADD},
				{"ENHN", "A", 3+1, colormap = "ENBL", colorframe = "A", colorflags = V_ADD},
				{"Goto", "Ready"}
			},
			
			["AltFire"] = {
				{"ENHN", "F", 3+1, action = RFW.WA_AxeLunge, colormap = "ENBL", colorframe = "F", colorflags = V_ADD},
				{"ENHN", "G", 3+1, action = RFW.WA_AxeHit, colormap = "ENBL", colorframe = "G", colorflags = V_ADD},
				{"ENHN", "H", 3+1, colormap = "ENBL", colorframe = "H", colorflags = V_ADD},
				{"ENHN", "I", 3+1, colormap = "ENBL", colorframe = "I", colorflags = V_ADD},
				{"ENHN", "A", 3+1, colormap = "ENBL", colorframe = "A", colorflags = V_ADD},
				{"Goto", "Ready"}
			}
		}
	}
)

freeslot("sfx_fl")

freeslot("MT_FLBALL")
freeslot("S_FLBALL")
mobjinfo[MT_FLBALL] = {
	spawnstate = S_FLBALL,
	spawnhealth = 1,
	seestate = S_NULL,
	seesound = sfx_none,
	reactiontime = 1,
	attacksound = sfx_none,
	painstate = S_NULL,
	painchance = 8192,
	painsound = sfx_none,
	meleestate = S_NULL,
	missilestate = S_NULL,
	deathstate = S_NULL,
	xdeathstate = S_NULL,
	deathsound = sfx_none,
	speed = 10,
	radius = 16*FRACUNIT,
	height = 32*FRACUNIT,
	dispoffset = 0,
	mass = 100,
	damage = 0,
	activesound = sfx_None,
	flags = MF_NOCLIP,
	raisestate = S_NULL
}

//
states[S_FLBALL] = {
	sprite = SPR_THOK,
	frame = B|FF_ADD|FF_TRANS80, //god damn it stjr add lighting is fucking broken this doesn't do shit
	tics = 2,
	nextstate = S_NULL
}

function RFW.WA_FlashBeam(p)
	//print(1)
	P_AngleRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle, zang = p.aiming, distance = 128*FU, steps = 3, tclip = true, lclip = true, ignore = p.mo, callback = P_SpawnMobj, arg = MT_FLBALL}
end

RFW.WP_flashlight = RFW.AddWeapon(1, { //only add weapons NOT in runtime (e.g no commands to add weapons) only add weapons in whitespace (if they're touching the very left edge of the screen)
	["WeaponName"] = "Flash-Light",
	["BobFunc"] = RFW.Bob_RampageBobSmallWeaps,
	["PickupAmmo"] = 0,
	["AmmoType"] = 0,
	["Priority"] = 250,
	["MinAmmo"] = 0,
		["States"] = {
			["Ready"] = {
				{"FLGT", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"FLGT", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"FLGT", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"FLGT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_fl},
				{"FLGT", "A", 1, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			},
			
			["Hold"] = {
				{"FLGT", "A", 1, action = RFW.WA_FlashBeam},
				{"FLGT", "A", 1, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			}
		}
	}
)

RFW.WP_lightning = RFW.AddWeapon(10, {
	["WeaponName"] = "WHERE THERES RAIN, THERES THUNDER",
	["BobFunc"] = RFW.Bob_RampageBobSmallWeaps,
	["PickupAmmo"] = 40,
	["AmmoType"] = 4,
	["MinAmmo"] = 2,
		["States"] = {
			["Ready"] = {
				{"GATL", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"GATL", "A", 0+1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"GATL", "A", 0+1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"GATL", "C", 1, action = RFW.WA_LightningShot},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"GATL", "B", 1, action = RFW.WA_LightningShot2},
				{"GATL", "B", 1+1, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			},
			
			["Flash"] = { //for easier weapon porting from stuff like zdoom mods, completely optional if not calling the flash state.
				{"GATT", "A", 1+1},
				{"GATT", "B", 1+1}
			},
		}
	}
)

function RFW.WA_KillerLanguage(p)
	//mega uber-offending facist finger blast
	S_StartSound(p.mo, sfx_FUCK1+P_RandomRange(0, 3))
	local targetlist = P_AngleRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle, zang = p.aiming, distance = 8192*FU, steps = 512, tclip = false, lclip = true, ignore = p.mo}
	if not next(targetlist) then return false end
	for i = 1, #targetlist do
		local target = targetlist[i][4]
		if target.type == MT_PLAYER then
			for i = 1, P_RandomRange(25, 35) do
				RFW.Bleed(target)
			end
			if CanPlayerHurtPlayer(p, target.player, 1, 0) == true then
				Playerdamage(target, p.mo, p.mo, 99999, 0, true)
			end
		else
			local hx = targetlist[1][1]
			local hy = targetlist[1][2]
			local hz = targetlist[1][3]
			//for i = 1, P_RandomRange(40, 50) do
			//	RFW.SparkCoordinate(target, hx, hy, hz)
			//end
			for i = 1, P_RandomRange(25, 35) do
				RFW.Bleed(target)
			end
			P_DamageMobj(target, p.mo, p.mo, 99999, 0)
		end
	end
end

function RFW.WA_KillerLanguage2(p)
	//mega uber-offending facist finger blast
	for i = 1, 25 do
		local targetlist = P_AngleRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle+FixedAngle(P_RandomRange(-10*FU, 10*FU)), zang = p.aiming, distance = 8192*FU, steps = 512, tclip = false, lclip = true, ignore = p.mo}
		if not next(targetlist) then return false end
		for i = 1, #targetlist do
			local target = targetlist[i][4]
			if target.type == MT_PLAYER then
				//for i = 1, P_RandomRange(25, 35) do
				//	RFW.Bleed(target)
				//end
				if CanPlayerHurtPlayer(p, target.player, 1, 0) == true then
					Playerdamage(target, p.mo, p.mo, 25, 0, true)
				end
			else
				local hx = targetlist[1][1]
				local hy = targetlist[1][2]
				local hz = targetlist[1][3]
				//for i = 1, P_RandomRange(40, 50) do
				//	RFW.SparkCoordinate(target, hx, hy, hz)
				//end
				//for i = 1, P_RandomRange(25, 35) do
				//	RFW.Bleed(target)
				//end
				P_DamageMobj(target, p.mo, p.mo, 25, 0)
			end
		end
	end
end

RFW.WP_offensive = RFW.AddWeapon(1, {
	["WeaponName"] = "Words that Break Bones (and Flesh).",
	["BobFunc"] = RFW.Bob_RampageBobSmallWeaps,
	["AmmoType"] = 0,
	["Priority"] = 9999,
	["MinAmmo"] = 0,
		["States"] = {
			["Ready"] = {
				{"TNT1", "A", 1},
				{"Loop"}
			},
			
			["Lower"] = {
				{"TNT1", "A", 0, action = RFW.WA_Lower},
				{"Loop"}
			},
			
			["Raise"] = {
				{"TNT1", "A", 0, action = RFW.WA_Raise},
				{"Loop"}
			},

			["Fire"] = {
				{"FUCK", "A", 1},
				{"FUCK", "B", 1},
				{"FUCK", "C", 1},
				{"FUCK", "D", 15, action = RFW.WA_KillerLanguage},
				{"FUCK", "E", 1},
				{"FUCK", "F", 1},
				{"FUCK", "G", 1},
				{"FUCK", "H", 1},
				{"FUCK", "I", 1},
				{"Goto", "Ready"}
			},
			
			["AltFire"] = {
				{"FUCK", "A", 3},
				{"FUCK", "B", 3},
				{"FUCK", "C", 3},
				{"FUCK", "D", 20, action = RFW.WA_KillerLanguage},
				{"FUCK", "D", 0, action = RFW.WA_Refire},
				{"FUCK", "E", 3},
				{"FUCK", "F", 3},
				{"FUCK", "G", 3},
				{"FUCK", "H", 3},
				{"FUCK", "I", 3},
				{"Goto", "Ready"}
			},
			
			["AltHold"] = {
				{"FUCK", "D", 3, action = RFW.WA_KillerLanguage2},
				{"FUCK", "D", 0, action = RFW.WA_Refire},
				{"FUCK", "E", 3},
				{"FUCK", "F", 3},
				{"FUCK", "G", 3},
				{"FUCK", "H", 3},
				{"FUCK", "I", 3},
				{"Goto", "Ready"}
			},
			
		}
	}
)

local function ccw(Ax,Bx,Cx,Ay,By,Cy) //nabbed this from a python guide
    return FixedMul((Cy-Ay), (Bx-Ax)) > FixedMul((By-Ay), (Cx-Ax))
end

local function intersect(Ax,Bx,Cx,Dx,Ay,By,Cy,Dy)
    return ccw(Ax,Cx,Dx,Ay,Cy,Dy) != ccw(Bx,Cx,Dx,By,Cy,Dy) and ccw(Ax,Bx,Cx,Ay,By,Cy) != ccw(Ax,Bx,Dx,Ay,By,Dy)
end

local function LineCollide(x, y, z, ox, oy, mo)
	local flags = mo.flags
	if flags & (MF_NOCLIP|MF_NOCLIPTHING) then return false end
	if not (flags & MF_SHOOTABLE) then return false end
	local mx = mo.x
	local my = mo.y
	local rad = mo.radius
	local mA = mo.x - rad //x 1
	local mB = mo.x + rad //x 2
	local mC = mo.y + rad //y
	local bruh = mo.z+mo.height
	if x >= mx-rad and x <= mx+rad and y >= my-rad and y <= my+rad then //if our coordinate is already in the hitbox we don't need to do math lmao
		local pos = mo.z
		if z > mo.height+pos then return false end
		if z < pos then return false end
		return true
	end
	if intersect(ox,x,mA,mB,oy,y,mC,mC,true,true) then
		local pos = mo.z
		if z > mo.height+pos then return false end
		if z < pos then return false end
		return true
	end
	local mC = mo.y - rad //new y
	if intersect(ox,x,mA,mB,oy,y,mC,mC,true,true) then
		local pos = mo.z
		if z > mo.height+pos then return false end
		if z < pos then return false end
		return true
	end
	local mA = mo.y - rad //y 1
	local mB = mo.y + rad //y 2
	local mC = mo.x + rad //x
	if intersect(ox,x,mC,mC,oy,y,mA,mB,true,true) then
		local pos = mo.z
		if z > mo.height+pos then return false end
		if z < pos then return false end
		return true
	end
	local mC = mo.x - rad //new x
	if intersect(ox,x,mC,mC,oy,y,mA,mB,true,true) then
		local pos = mo.z
		if z > mo.height+pos then return false end
		if z < pos then return false end
		return true
	end
	return false
end

local function P_SpawnRailColor(x, y, z, p, mo)
	local rail = P_SpawnMobj(x, y, z, mo)
	rail.color = p.secondcolor
	return rail
end

local function P_KarasawaRaycast(args)
	// Arguments
	local x = ParseArg(args, "x", 0)
	local y = ParseArg(args, "y", 0)
	local z = ParseArg(args, "z", 0)
	local ang = ParseArg(args, "ang", 0)
	local zang = ParseArg(args, "zang", 0)
	local distance = ParseArg(args, "distance", 240*FU)
	local steps = ParseArg(args, "steps", 32)
	local tracer = ParseArg(args, "tracer")
	local tclip = ParseArg(args, "tclip")
	local lclip = ParseArg(args, "lclip")
	local rad = ParseArg(args, "rad")
	local i = ParseArg(args, "i")
	local s = ParseArg(args, "s")
	local d = ParseArg(args, "d")
	local dt = ParseArg(args, "dt")
	local force = ParseArg(args, "force")
	local ignore = ParseArg(args, "ignore")

	if not (raycastMobj and raycastMobj.valid) then
		raycastMobj = P_SpawnMobj(0,0,0, MT_GREENRAY)
	end

	local collisionlist = {}
	local collisionset = {}
	local vx = FixedMul(cos(ang), cos(zang))
	local vy = FixedMul(sin(ang), cos(zang))
	local vz = sin(zang)
	local ox
	local oy
	local oz

	local move = distance/steps
	
	//local bruhhhh = 0

	for stepcount = 1, steps do
		ox = x
		oy = y
		oz = z
		x = $ + FixedMul(move, vx)
		y = $ + FixedMul(move, vy)
		z = $ + FixedMul(move, vz)
		
		if tracer and (s and s.valid) and (s.player and s.player.valid) then
			P_SpawnRailColor(x, y, z, s.player, tracer)
		end
		
		if (raycastMobj and raycastMobj.valid) then
			P_SetOrigin(raycastMobj, x, y, z) //trouble area here, says the mobj doesnt exist
		end

		if searchBlockmap("objects", function(ref, object)
			if object == ignore then return nil end
			if collisionset[object] then print("set") return nil end
			if LineCollide(x, y, z, ox, oy, object) == true then
				table.insert(collisionlist, {x, y, z, object})
				collisionset[object] = true
				RFW.ExplodePoint(x, y, z, rad, i, s, d, dt, force)
				if tclip == true or tclip == 1 then return true
				else return nil end
			end
		end, raycastMobj) == false then break end
	
		if lclip == true or lclip == 1 then
			local sect = raycastMobj.subsector.sector
			local floorheight = sect.floorheight
			local ceilheight = sect.ceilingheight
			if sect.f_slope then
				local slope = sect.f_slope
				local vectorx = x-slope.o.x //distance from origin x
				local vectory = y-slope.o.y //distance from origin y
				local angle = slope.xydirection //horizontal angle of slope
				local dist = FixedMul(vectorx, cos(angle))+FixedMul(vectory, sin(angle)) //distance from origin
				local vectorz = FixedMul(tan(slope.zangle), dist) //the slope's distance from origin z at this specific part of the slope
				floorheight = vectorz + slope.o.z
			end
			if sect.c_slope then
				local slope = sect.c_slope
				local vectorx = x-slope.o.x //distance from origin x
				local vectory = y-slope.o.y //distance from origin y
				local angle = slope.xydirection //horizontal angle of slope
				local dist = FixedMul(vectorx, cos(angle))+FixedMul(vectory, sin(angle)) //distance from origin
				local vectorz = FixedMul(tan(slope.zangle), dist) //the slope's distance from origin z at this specific part of the slope
				ceilheight = vectorz + slope.o.z
			end
			if z < floorheight or z > ceilheight then //in floor or ceiling
				if callback2 then
					RFW.ExplodePoint(x-FixedMul(move, vx), y-FixedMul(move, vy), z-FixedMul(move, vz), rad, i, s, d, dt, force)
				end
				break
			end
			local shouldbreak = 0
			for fof in sect.ffloors() do //check fofs
				if not (fof.flags & FOF_SOLID) then continue end
				if not (fof.flags & FOF_EXISTS) then continue end
				local topheight = fof.topheight
				local bottomheight = fof.bottomheight
				if fof.t_slope then
					local slope = fof.t_slope
					local vectorx = x-slope.o.x //distance from origin x
					local vectory = y-slope.o.y //distance from origin y
					local angle = slope.xydirection //horizontal angle of slope
					local dist = FixedMul(vectorx, cos(angle))+FixedMul(vectory, sin(angle)) //distance from origin
					local vectorz = FixedMul(tan(slope.zangle), dist) //the slope's distance from origin z at this specific part of the slope
					topheight = vectorz + slope.o.z
				end
				if fof.b_slope then
					local slope = fof.b_slope
					local vectorx = x-slope.o.x //distance from origin x
					local vectory = y-slope.o.y //distance from origin y
					local angle = slope.xydirection //horizontal angle of slope
					local dist = FixedMul(vectorx, cos(angle))+FixedMul(vectory, sin(angle)) //distance from origin
					local vectorz = FixedMul(tan(slope.zangle), dist) //the slope's distance from origin z at this specific part of the slope
					bottomheight = vectorz + slope.o.z
				end
				if (z <= topheight and z >= bottomheight) then
					shouldbreak = 1
					break
				end
			end
			if shouldbreak == 1 then
				RFW.ExplodePoint(x-FixedMul(move, vx), y-FixedMul(move, vy), z-FixedMul(move, vz), rad, i, s, d, dt, force)
				break
			end
			if R_PointInSubsectorOrNil(x, y) == nil then //check walls
				//bruhhhh = $ + 1
				RFW.ExplodePoint(x-FixedMul(move, vx), y-FixedMul(move, vy), z-FixedMul(move, vz), rad, i, s, d, dt, force)
				break
			end
		end
	end
	P_RemoveMobj(raycastMobj)
	if not next(collisionlist) then
		RFW.ExplodePoint(x, y, z, rad, i, s, d, dt, force)
	end
	return collisionlist
end

function RFW.WA_KarasawaHitscan(p, damage, range, spread, rad, force, peirce, tracer)
	local nhspread = 0
	local nvspread = 0
	if spread then
		nhspread = FixedAngle(P_RandomRange(-spread, spread))
		nvspread = FixedAngle(P_RandomRange(-spread, spread))
	end
	local d = nil
	if damage and type(damage) == "number" then
		d = damage
	elseif damage and type(damage) == "table" then
		d = P_RandomRange(damage[1], damage[2])
	end
	local targetlist = P_KarasawaRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle+nhspread, zang = p.aiming+nvspread, distance = range, steps = FixedInt(range)/16, tclip = (not pierce), lclip = true, ignore = p.mo, callback = (tracer) and P_SpawnRailTrace or nil, arg = {p, tracer}, rad = rad, i = p.mo, s = p.mo, d = d, force = force, tracer = tracer}
end

function RFW.WA_KarasawaCharge(p, mx)
	if p.mo.karacharge == nil then
		p.mo.karacharge = 0
	end
	p.mo.karacharge = min($+1, mx)
end

freeslot("sfx_kchrg1", "sfx_kchrg2", "sfx_kchrg3", "sfx_kchrg4", "sfx_kchrg5", "sfx_kchrg6")

function RFW.WA_KaraChargeNoise(p, mx)
	if p.mo.karacharge == nil then
		p.mo.karacharge = 0
	end
	//print(sfx_kchrg1)
	//print(sfx_kchrg2)
	//print(sfx_kchrg3)
	//print(sfx_kchrg4)
	//print(sfx_kchrg5)
	//print(sfx_kchrg6)
	local cx = p.mo.karacharge
	if cx >= mx then
		if not S_SoundPlaying(p.mo, sfx_kchrg6) then
			S_StartSound(p.mo, sfx_kchrg6)
		end
	else//if not (leveltime % 5) then
		local s = max(min(FixedInt(((cx*FU)/(mx-1))*5), 4), 0)
		//print(sfx_kchrg1+(s))
		if not S_SoundPlaying(p.mo, sfx_kchrg1+(s)) then
			S_StopSoundByID(p.mo, sfx_kchrg1)
			S_StopSoundByID(p.mo, sfx_kchrg2)
			S_StopSoundByID(p.mo, sfx_kchrg3)
			S_StopSoundByID(p.mo, sfx_kchrg4)
			S_StopSoundByID(p.mo, sfx_kchrg5)
			S_StartSound(p.mo, sfx_kchrg1+(s))
		end
	end
end

function RFW.WA_KarasawaHitscan2(p, damage, range, spread, rad, force, peirce, tracer, mx)
	if p.mo.karacharge == nil then
		p.mo.karacharge = 0
	end
	for i = 0, 5 do
		S_StopSoundByID(p.mo, sfx_kchrg1+i)
	end
	local chf = p.mo.karacharge*FU
	local mxf = mx*FU 
	local percent = FixedDiv(chf, mxf)
	local d = nil
	if damage then
		local d1 = damage[1]
		local d2 = damage[2]
		d = FixedInt(FixedMul((d2-d1)*FU, percent)+(d1*FU))
	end
	local r1 = range[1]
	local r2 = range[2]
	local r = FixedMul((r2-r1), percent)+r1
	local rd1 = rad[1]
	local rd2 = rad[2]
	local rd = FixedMul((rd2-rd1), percent)+rd1
	local f1 = force[1]
	local f2 = force[2]
	local f = FixedInt(FixedMul((f2-f1)*FU, percent)+(f1*FU))
	local nhspread = 0
	local nvspread = 0
	if spread then
		nhspread = FixedAngle(P_RandomRange(-spread, spread))
		nvspread = FixedAngle(P_RandomRange(-spread, spread))
	end
	local targetlist = P_KarasawaRaycast{x = p.mo.x, y = p.mo.y, z = RFW.StupidZBullshit(p), ang = p.mo.angle+nhspread, zang = p.aiming+nvspread, distance = r, steps = FixedInt(r)/16, tclip = (not pierce), lclip = true, ignore = p.mo, rad = rd, i = p.mo, s = p.mo, d = d, force = f, tracer = tracer}
	p.mo.karacharge = 0
end

freeslot("sfx_karafr")

function RFW.WA_UseKaraAmmo(p, fire, amount, mx) //fire: 0 = ammo, 1 = ammo1, 2 = ammo2.
	if fire == nil then
		fire = 0
	end
	if p.mo.karacharge == nil then
		p.mo.karacharge = 0
	end
	if amount == nil then
		amount = {1, 5}
	end
	local mina = amount[1]
	local maxa = amount[2]
	local chf = p.mo.karacharge*FU
	local mxf = mx*FU 
	local percent = FixedDiv(chf, mxf)
	local am = FixedInt(FixedMul((maxa-mina)*FU, percent)+(mina*FU))
	local atype = (fire == 1) and "AmmoType1" or (fire == 2) and "AmmoType2" or "AmmoType"
	local ammoid = RFW.Weapons[p.slot][p.weapon][atype]
	//if RFW.WA_AmmoCheck(p, ammoid, RFW.Weapons[p.slot][p.weapon]["MinAmmo"]) //not needed because ammo checker at start of firing, if you need to check other ammo types then do them manually
	p.ammolist[ammoid] = max($ - am, 0)
end

RFW.WP_karasawa = RFW.AddWeapon(6, {
	["WeaponName"] = "Karasawa",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 3,
	["PickupAmmo"] = 40,
	["Priority"] = 500,
	["AmmoType"] = 4,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = { //RFW.WA_PlasmaIdle2
				{"KRSW", "F", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "F"},
				{"KRSW", "F", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "F"},
				{"KRSW", "F", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "F"},
				{"KRSW", "G", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "G", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "G", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "H", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "H", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "H", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "I", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "I", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "I", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "J", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "J"},
				{"KRSW", "J", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "J"},
				{"KRSW", "J", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "J"},
				{"KRSW", "I", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "I", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "I", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "I"},
				{"KRSW", "H", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "H", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "H", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "H"},
				{"KRSW", "G", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "G", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "G", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "G"},
				{"KRSW", "F", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "F"},
				{"KRSW", "F", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "F"},
				{"KRSW", "F", 1, action = RFW.WA_PlasmaIdle2, colormap = "KRSF", colorframe = "F"},
				{"Loop"}
			},
			
			/*["KFlash"] = {
				{"MGNM", "F", 2},
				{"MGNM", "G", 2},
				{"MGNM", "H", 2},
				{"MGNM", "I", 2},
				{"MGNM", "J", 6},
				{"MGNM", "I", 2},
				{"MGNM", "H", 2},
				{"MGNM", "G", 2},
				{"MGNM", "F", 2}
			},*/
			
			["Lower"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"KRSW", "A", 1, action = RFW.WA_Lower}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"KRSW", "A", 1, action = RFW.WA_Raise},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"KRSW", "F", 1, colormap = "KRSF", colorframe = "F", action = RFW.WA_KarasawaCharge, arg1 = TICRATE*3/2},
				{"TNT", "A", 0, action = RFW.WA_KaraChargeNoise, arg1 = TICRATE*3/2},
				{"TNT", "A", 0, action = RFW.WA_Refire},
				{"Goto", "Boom"}
			},
			
			["Boom"] = {
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_karafr},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"TNT", "A", 0, action = RFW.WA_UseKaraAmmo, arg1 = 0, arg2 = {1,5}, arg3 = TICRATE*3/2},
				//{"KRSW", "B", 3, action = RFW.WA_KarasawaHitscan, colormap = "KRSF", colorframe = "B", arg1 = nil, arg2 = 512*FU, arg3 = nil, arg4 = 192*FU, arg5 = 30, arg6 = false, arg7 = MT_RAILTRAIL},
				{"KRSW", "B", 3, action = RFW.WA_KarasawaHitscan2, colormap = "KRSF", colorframe = "B", arg1 = {20, 192}, arg2 = {256*FU, 640*FU}, arg3 = nil, arg4 = {192*FU/3, 192*FU}, arg5 = {5, 30}, arg6 = false, arg7 = MT_RAILTRAIL, arg8 = TICRATE},
				{"KRSW", "C", 3, colormap = "KRSF", colorframe = "C"}, //damage, range, spread, rad, force, peirce, tracer
				{"KRSW", "D", 3, colormap = "KRSF", colorframe = "D", ready = true, bob = false},
				{"KRSW", "E", 3, colormap = "KRSF", colorframe = "E", ready = true, bob = false},
				{"KRSW", "A", 9, ready = true, bob = false},
				{"Goto", "Ready"}
			},
			
			/*["Flash"] = {
				{"KRSF", "B", 2},
				{"KRSF", "C", 2},
				{"KRSF", "D", 2},
				{"KRSF", "E", 2},
				//{"KRSF", "A", 1}
			},*/
		}
	}
)

freeslot("sfx_plas1")

RFW.WP_plasmarifle = RFW.AddWeapon(6, {
	["WeaponName"] = "Plasma Rifle",
	["BobFunc"] = RFW.Bob_RampageBob,
	["HoldSprite"] = SPR_WPVW,
	["HoldFrame"] = 9,
	["PickupAmmo"] = 40,
	["AmmoType"] = 4,
	["MinAmmo"] = 1,
		["States"] = {
			["Ready"] = { //sfx_KARAID
				{"PLZM", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "PLZC", colorframe = "A"},
				{"PLZM", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "PLZC", colorframe = "A"},
				{"PLZM", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "PLZC", colorframe = "B"},
				{"PLZM", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "PLZC", colorframe = "B"},
				{"PLZM", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "PLZC", colorframe = "C"},
				{"PLZM", "A", 1, action = RFW.WA_PlasmaIdle, colormap = "PLZC", colorframe = "C"},
				{"Loop"}
			},
			
			["Lower"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"PLZM", "A", 0+1, action = RFW.WA_Lower, colormap = "PLZC", colorframe = "A"}, //action instead of just using the 4th index cause srb2 on some BULLSHIT and wont properly synch functions in tables UNLESS I use a string key, god fucking damn it.
				{"Loop"}
			},
			
			["Raise"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"PLZM", "A", 0+1, action = RFW.WA_Raise, colormap = "PLZC", colorframe = "A"},
				{"Loop"}
			},
			
			["Fire"] = {
				{"TNT", "A", 0, action = RFW.WA_PlasmaUnidle},
				{"TNT", "A", 0, action = RFW.WA_PlaySound, arg1 = sfx_plas1},
				{"TNT", "A", 0, action = RFW.WA_UseAmmo, arg1 = 0, arg2 = 1},
				{"TNT", "A", 0, action = RFW.Sound, arg1 = 1024*FU},
				{"PLZM", "A", 2, action = RFW.WA_CustomProjectileSecondColor, arg1 = MT_PLASMABALL, colormap = "PLZC", colorframe = "E"},
				{"PLZM", "A", 1, colormap = "PLZC", colorframe = "D"},
				{"PLZM", "A", 20, action = RFW.WA_Refire},
				{"Goto", "Ready"}
			},
		}
	}
)

//RFW.ExplodePoint(x, y, z, rad, i, s, d, dt, force)

COM_AddCommand("administerthyfinger", function(p)
	G_SetUsedCheats(false)
	RFW.GivePlayerWeapon(p, 1, RFW.WP_offensive)
end, COM_ADMIN)

COM_AddCommand("andtherewasafingerparty", function(p)
	G_SetUsedCheats(false)
	for i in players.iterate do
		RFW.GivePlayerWeapon(i, 1, RFW.WP_offensive)
	end
end, COM_ADMIN)